/**
 * 将路径中字符串参数转化为对应对象
 * http://127.0.0.1:8002/user?id=1&name=xiaowang
 * {id:1,name:"xiaowang"}
 */
//如果要用可索引接口约束对象，index一般默认都是string
// interface IData {
//     [index:string]:string | number
// }
// const obj3:IData = {

// }
// obj3.id = 1
// obj3.name = "xiaowang"
// obj3["name"] = "xiaofei"

// //如果要用可索引接口约束数组，index默认一般都是number
// interface IData2 {
//     [index:number]:number
// }
// const array4:IData2 = []
// array4[1] = 100

const path = "http://127.0.0.1:8002/user?id=1&name=xiaowang"
interface IData {
    [index:string]:string
}
function pathParse(path:string){
    let obj:IData = {}
    const url = path.substring(path.indexOf("?"))
    // 浏览器默认提供对象
    const params = new URLSearchParams(url)
    console.log(params);
    for (const key of params.entries()) {
        console.log("Key",key);
        obj[key[0]] = key[1]
    }
    console.log(obj);
    
}
pathParse(path)

export {}



